@include('header')
<div class="body_bg">
	<div class="container">
	<!-- 主列表 -->
		<ul class="ul_nav left">
			<li >
				<a class="li_01 " href="/invitation/1/edit">编辑喜帖</a>
			</li>
			<li class="active">
				<a class="li_02 active" href="/invitation/list">查看喜帖</a>
			</li>
			<li>
				<a class="li_04" href="/invitation/bless">祝福留言</a>
			</li>
			<li >
				<a class="li_05" href="/invitation/attend">出席名单</a>
			</li>
		</ul>
	<div class="left container_box">
		<div class="tit">
			<p><a class="active" href="">已制作过的喜帖</a></p>
		</div>
		
			<ul class="invitation_list" id="invitation_list">

			</ul>
	</div>
	</div>
</div>
<script type="text/javascript">
	function edit(id){
		// location.href="/invitation/"+id+"/edit";
	}
	function invitation_delete(id){
		var r = confirm("确定要删除？");
		if(r){
				$.ajax({
				type:"DELETE",
				url:"/api/v1/invitation/"+id,
				success:function(data){
					if(!data.error){
						location.href = '/invitation/list';
					}
				}
			})
		}
		
	}
	//获取全部喜帖
	$.ajax({
	    type: "GET",
	    url:'/api/v1/invitation',
	    success: function(data) {
	      if (!data.error) {
	          var allinvitation = data.result;
	          $.each(allinvitation, function(i,val){  
	            var tpl = '<li id="'+val.id+'" onclick="edit('+val.id+')" >\
	                        <div class="front">\
	                        <div class="head">\
	                          <span class="boy_name">'+val.boy_name+'&nbsp<span style="font-size:16px">&</span></span>\
	                          <span class="girl_name">'+val.girl_name+'</span>\
	                          <span class="create_at">'+val.created_at+'</span>\
	                        </div>\
	                          <img src="'+val.head_dir+'?imageView2/1/w/300/h/200">\
	                        </div>\
	                        <div class="back">\
	                          <div class="left">\
	                            <div class="qrcode_show" id="'+val.id+'"></div>\
	                            <span>喜帖二维码</span>\
	                          </div>\
	                          <div class="right">\
	                            <div class="qrcode_thank" id="'+val.id+'"></div>\
	                            <span>感谢卡二维码</span>\
	                          </div>\
	                        </div>\
	                        <div class="footer">\
								<button class="btn btn-default"  onclick="invitation_delete('+val.id+')" style="margin-right:15px;">删除</button>\
								<a class="btn btn-default"  href="/invitation/'+val.id+'/edit">编辑</a>\
	                        </div>\
	                      </li>';
	            $("#invitation_list").append(tpl);
	          });
			//生成模板的二维码
	        $(".qrcode_show").each(function(){
	          var url = 'http://chinalove99.net:83/invitation/'+$(this).attr('id');
	          $(this).qcode({  
	              text : url,  
	              type : 'cn',  
	              width : 100,  
	              height : 100  
	          })
	        })
	        //生成模板的二维码
	        $(".qrcode_thank").each(function(){
	          var url = 'http://chinalove99.net:83/invitation/'+$(this).attr('id')+'/thanks';
	          $(this).qcode({  
	              text : url,  
	              type : 'cn',  
	              width : 100,  
	              height : 100  
	          })
	        })
	      };    
	    }
	}); 

</script>
@include('footer')